package com.dangz.dans.controller;


import com.dangz.dans.entity.CommonResponse;
import com.dangz.dans.response.ApiEnum;
import com.dangz.dans.response.CodeEnum;
import com.dangz.dans.response.TypeEnum;
import com.dangz.dans.utils.EncryptedDataUtils;
import com.dangz.dans.utils.WxUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("dans/encrypte")
@Api(tags = "wx_解密")
public class EncryptedDataController {
  @ApiOperation(value = "获取encryptedData信息", notes = "POST方式")
  @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "header", value = "Authorization", name = HttpHeaders.AUTHORIZATION, dataType = "String")
      @ApiImplicitParam(paramType = "query", name = "encryptedData", value = "encryptedData", dataType = "String", required = true),
      @ApiImplicitParam(paramType = "query", name = "session_key", value = "session_key", dataType = "String", required = true),
      @ApiImplicitParam(paramType = "query", name = "iv", value = "iv", dataType = "String", required = true)
  })
  @GetMapping("getEncryptedData")
  public CommonResponse decode(String encryptedData, String session_key, String iv) {
    CommonResponse commonResponse = null;
    String str = EncryptedDataUtils.decode(encryptedData, session_key, iv);
    if (StringUtils.isNotEmpty(str)) {
      commonResponse = new CommonResponse(TypeEnum.getFullRespCode(TypeEnum.Success,
          ApiEnum.XTGL, CodeEnum.SUCCESS_SERVICE_LOCAL), CodeEnum.SUCCESS_SERVICE_LOCAL.getInfo(), str);
    } else {
      commonResponse = new CommonResponse(TypeEnum.getFullRespCode(TypeEnum.Success,
          ApiEnum.XTGL, CodeEnum.SUCCESS_NO_DATA_LOCAL), CodeEnum.SUCCESS_NO_DATA_LOCAL.getInfo());
    }
    return commonResponse;
  }
}
